package models.sys;

import models.BaseModel;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Table;

import packaged.SessionManager;
import play.Play;
import play.db.jpa.JPABase;
import play.mvc.Scope;

@MappedSuperclass
public abstract class SystemModel extends BaseModel {
    public static boolean trash = "true".equals(Play.configuration.getProperty("system.model.trash"));

    @Column(columnDefinition="INT default 1")   //默认值为1(未锁定)
    public Integer enabled;

    @Override
    public <T extends JPABase> T delete() {
        if (trash) {
            Table table = this.getClass().getAnnotation(Table.class);
            if (table != null) {
                new Trash(table.name(), this.toJSON(),AdminUser.findByInfo(SessionManager.getUserInfo(Scope.Session.current()))).save();
            }
        }
        return super.delete();
    }
}
